home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1995 February: Tool Chest / Dev.CD Feb 95 / Dev.CD Feb 95.toast / Tool Chest / Interfaces / Universal Interfaces 1.0 / CIncludes / fstream.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-04  |  4.9 KB  |  179 lines  |  [TEXT/MPS ]

  1. /*
  2.  *------------------------------------------------------------------------
  3.  * Copyright:
  4.  *      © 1993 by Apple Computer Inc.  all rights reserved.
  5.  *
  6.  * Project:
  7.  *      PowerPC C++ Streams Library
  8.  *
  9.  * Filename:
  10.  *      fstream.h
  11.  *
  12.  * Created:
  13.  *      (unknown)
  14.  *
  15.  * Modified:
  16.  *      Date     Engineer       Comment
  17.  *      -------- -------------- ------------------------------------------
  18.  *      12/17/93 Rudy Wang      Made this file universal.
  19.  *------------------------------------------------------------------------
  20.  */
  21. #ifndef __FSTREAMH__
  22. #define __FSTREAMH__        1
  23.  
  24. #include <iostream.h>
  25.  
  26. #ifdef powerc
  27. #pragma options align=power
  28. #endif
  29.  
  30. class filebuf : public streambuf
  31. {
  32.  
  33. #ifdef powerc
  34. public:
  35.         static const int openprot;      // default protection mode for open
  36. #endif
  37.  
  38. public:
  39.                         filebuf();
  40.                         filebuf(int fd);
  41.                         filebuf(int fd, char* p, int l);
  42.                         ~filebuf();
  43.         int             is_open()       { return opened; }
  44.         int             fd()            { return xfd; }
  45. #ifdef applec
  46.         filebuf*        open(const char *name, int om);
  47. #else
  48.         filebuf*        open(const char *name, int om, int prot = openprot);
  49. #endif
  50.         filebuf*        attach(int fd);
  51.         filebuf*        close();
  52.  
  53. public:
  54.         virtual int     overflow(int = EOF);
  55.         virtual int     underflow();
  56.         virtual int     sync();
  57.         virtual streampos seekoff(streamoff, ios::seek_dir, int);
  58.         virtual streambuf* setbuf(char* p, int len);
  59.         virtual int     xsputn(const char* s, int n);
  60.  
  61. protected:
  62.         int             xfd;    
  63.         int             mode;
  64.         char            opened;
  65.         streampos       last_seek;
  66.         char*           in_start;
  67.         int             last_op();
  68.         char            lahead[2];
  69.  
  70. };  // class filebuf
  71.  
  72.  
  73. class fstreambase : virtual public ios
  74. {
  75.  
  76. public:
  77.                         fstreambase();
  78. #ifdef applec
  79.                         fstreambase(const char* name, int mode);
  80. #else
  81.                         fstreambase(const char* name, int mode, int prot = filebuf::openprot);
  82. #endif
  83.                         fstreambase(int fd);
  84.                         fstreambase(int fd, char* p, int l);
  85.                         ~fstreambase();
  86. #ifdef applec
  87.         void            open(const char* name, int mode);
  88. #else
  89.         void            open(const char* name, int mode, int prot = filebuf::openprot);
  90. #endif
  91.         void            attach(int fd);
  92.         void            close();
  93.         void            setbuf(char* p, int l);
  94.         filebuf*        rdbuf()         { return &buf; }
  95.  
  96. private:
  97.         filebuf         buf;
  98.  
  99. protected:
  100.         void            verify(int);
  101.  
  102. };  // class fstreambase
  103.  
  104.  
  105. class ifstream : public fstreambase, public istream
  106. {
  107.  
  108. public:
  109.                         ifstream();
  110. #ifdef applec
  111.                         ifstream(const char* name, int mode = ios::in);
  112. #else
  113.                         ifstream(const char* name, int mode = ios::in, int prot = filebuf::openprot);
  114. #endif
  115.                         ifstream(int fd);
  116.                         ifstream(int fd, char* p, int l);
  117.                         ~ifstream();
  118. #ifdef applec
  119.         void            open(const char* name, int mode = ios::in);
  120. #else
  121.         void            open(const char* name, int mode = ios::in, int prot = filebuf::openprot);
  122. #endif
  123.         filebuf*        rdbuf()         { return fstreambase::rdbuf(); }
  124.  
  125. };  // class ifstream
  126.  
  127.  
  128. class ofstream : public fstreambase, public ostream
  129. {
  130.  
  131. public:
  132.                         ofstream();
  133. #ifdef applec
  134.                         ofstream(const char* name, int mode = ios::out);
  135. #else
  136.                         ofstream(const char* name, int mode = ios::out, int prot = filebuf::openprot);
  137. #endif
  138.                         ofstream(int fd);
  139.                         ofstream(int fd, char* p, int l);
  140.                         ~ofstream();
  141. #ifdef applec
  142.         void            open(const char* name, int mode = ios::out);
  143. #else
  144.         void            open(const char* name, int mode = ios::out, int prot = filebuf::openprot);
  145. #endif
  146.         filebuf*        rdbuf()         { return fstreambase::rdbuf(); }
  147.  
  148. };  // class ofstream
  149.  
  150.  
  151. class fstream : public fstreambase, public iostream
  152. {
  153.  
  154. public:
  155.                         fstream();
  156. #ifdef applec
  157.                         fstream(const char* name, int mode);
  158. #else
  159.                         fstream(const char* name, int mode, int prot = filebuf::openprot);
  160. #endif
  161.                         fstream(int fd);
  162.                         fstream(int fd, char* p, int l);
  163.                         ~fstream();
  164. #ifdef applec
  165.         void            open(const char* name, int mode);
  166. #else
  167.         void            open(const char* name, int mode, int prot = filebuf::openprot);
  168. #endif
  169.         filebuf*        rdbuf()         { return fstreambase::rdbuf(); }
  170.  
  171. };  // class fstream
  172.  
  173.  
  174. #ifdef powerc
  175. #pragma options align=reset
  176. #endif
  177.  
  178. #endif
  179.